import jieba


txt=open(r"西游记.txt", "rb").read()


excludes = { "一个", "那里", "怎么", "我们", "不知","两个","甚么","只见", "不是", "原来", "不敢", "闻言", "如何","什么"}


words = jieba.lcut(txt)

counts = {}
for word in words:
    if len(word) == 1:
    elif word == "八戒" or word == "天蓬元帅":
        rword = "悟能"
    elif word == "行者" or word == "大圣" or word == "老孙":
        rword = "悟空"
    elif word == "师父" or word == "三藏" or word == "长老":
        rword = "唐僧"
    elif word == "悟净" or word == "沙和尚":
        rword = "沙僧"
    else:
        rword = word
        counts[rword] = counts.get(rword, 0) + 1


for word in excludes:

        del counts[word]


items = sorted(counts.items())
items.sort()


